Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

453 ega api funcs #458

Merged
merged 9 commits into from
Sep 30, 2024
Merged

453 ega api funcs #458

merged 9 commits into from
Sep 30, 2024

Conversation

anncatton
Copy link
Contributor

@anncatton anncatton commented Sep 24, 2024

Adds necessary API calls for permissions flow.

EGA Job

  • adds dacId as a config value, for referencing the ICGC DAC id
  • adds safe parsing to all responses, including for missing types on access and refresh token calls (from PR 457)
  • adds extended AxiosError classes for 404 and 429 errors
  • adds functions for all ega API calls needed to support the permissions flow. Adds success/failure returns to these, i'm thinking these can be used in the main ega function to populate a JobReport like we have for the other batch jobs
  • adds expiresAtUtc to approved apps db query to be used as expires_at value in ApprovePermissionRequest
  • creates separate functions for retrieving + parsing the approved users list, instead of reusing those for the CSV setup (which has unneeded extra fields). The intention is to remove all the CSV-related code after the new implementation is completed
  • adds util functions for creating permission-related request objects. These will be used in 454

Types

  • adds zod types for EGA responses + supporting custom entity types
  • adds regular ts types for request params, these do not need zod validation
  • adds safeParseArray utility func to validate items in list responses (thanks @joneubank !)
  • adds Result type for

Documentation

  • adds DAC_ID to .env.example + README

Dependencies

  • adds zod, bumps typescript version

Dev testing

  • updates userJwt expiry value

@anncatton anncatton marked this pull request as ready for review September 26, 2024 12:30
Comment on lines 79 to 110
export type ZodResultAccumulator<T> = { success: T[]; failure: ZodError[] };
/**
* Parses an array of Zod SafeParseReturnType results into success (successful parse) and failure (parsing error)
* @param acc ZodResultAccumulator<T>
* @param item z.SafeParseReturnType<T, T>
* @returns ZodResultAccumulator<T>
*/
const resultReducer = <T>(acc: ZodResultAccumulator<T>, item: z.SafeParseReturnType<T, T>) => {
if (item.success) {
acc.success.push(item.data);
} else {
acc.failure.push(item.error);
}
return acc;
};

/**
* Run Zod safeParse for Schema T on an array of items, and split results by SafeParseReturnType 'success' or 'error'.
* @params schema<T>
* @params data unknown[]
* @returns { success: [], failure: [] }
*/
export const safeParseArray = <T extends ZodTypeAny>(
schema: T,
data: Array<unknown>,
): ZodResultAccumulator<z.infer<T>> =>
data
.map((i) => schema.safeParse(i))
.reduce<ZodResultAccumulator<z.infer<T>>>((acc, item) => resultReducer(acc, item), {
success: [],
failure: [],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel like this file is getting overloaded, kind of a dumping ground. This new stuff belongs in a dedicated file for zodSafeParseArray.ts or similar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@anncatton anncatton merged commit ab2e9bc into 452-ega-auth-client Sep 30, 2024
0 of 2 checks passed
@anncatton anncatton deleted the 453-ega-api-funcs branch September 30, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants